﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace POVRay {
    public class ColorListPigment : Pigment {
        protected enum ColorListPattern { //the number after the underscore specifies the number of pigments/colors
            Checker_2, Hexagon_3, Brick_2
        }

        protected ColorListPattern Pattern { get; set; }
        protected Pigment Pigment1 { get; set; }
        protected Pigment Pigment2 { get; set; }
        protected Pigment Pigment3 { get; set; }

        protected float? BrickSize { get; set; }
        protected float? MortarSize { get; set; }

        protected ColorListPigment() { }
        
        public static ColorListPigment CheckerColorListPigment(Pigment pigment1, Pigment pigment2) {
            return new ColorListPigment() { Pattern = ColorListPattern.Checker_2, Pigment1 = pigment1, Pigment2 = pigment2  };
        }

        public static ColorListPigment HexagonColorListPigment(Pigment pigment1, Pigment pigment2, Pigment pigment3) {
            return new ColorListPigment() { Pattern = ColorListPattern.Hexagon_3, Pigment1 = pigment1, Pigment2 = pigment2, Pigment3 = pigment3 };
        }

        public static ColorListPigment BrickColorListPigment(Pigment pigment1, Pigment pigment2, float? brickSize, float? mortarSize) {
            return new ColorListPigment() { Pattern = ColorListPattern.Brick_2, Pigment1 = pigment1, Pigment2 = pigment2, BrickSize = brickSize, MortarSize = mortarSize };
        }

        protected String PatternKeyword(ColorListPattern pattern) {
            switch (pattern) {
                case ColorListPattern.Checker_2: return "checker";
                case ColorListPattern.Hexagon_3: return "hexagon";
                case ColorListPattern.Brick_2: return "brick";
                default: return "?";
            }
        }

        public override string ToString(int level) {
            StringBuilder sb = new StringBuilder();

            sb.Append("pigment { ");
            sb.Append(Scene.Indentation(level + 1) + PatternKeyword(Pattern) + " ");


            sb.Append(Scene.Indentation(level + 1) + Pigment1.ToString(level + 1) + ", ");
            sb.Append(Scene.Indentation(level + 1) + Pigment2.ToString(level + 1));
            if (Pattern == ColorListPattern.Hexagon_3) sb.Append(", " + Scene.Indentation(level + 1) + Pigment3.ToString(level + 1));

            if (BrickSize.HasValue) sb.Append(Scene.Indentation(level+1) + "brick_size " + BrickSize.Value.POVRayString());
            if (MortarSize.HasValue) sb.Append(Scene.Indentation(level + 1) + "mortar " + MortarSize.Value.POVRayString());

            sb.Append(GeneralParameters(level + 1));
            sb.Append(Scene.Indentation(level) + "}");

            return sb.ToString();
        }
    }
}
